package cn.tedu.lbs.article.web.controller;

import cn.tedu.lbs.article.web.service.ArticleService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.content.param.ArticleActionParam;
import com.tarena.lbs.pojo.content.param.ArticleContentParam;
import com.tarena.lbs.pojo.content.query.ArticleQuery;
import com.tarena.lbs.pojo.content.vo.ArticleActionPageResultVO;
import com.tarena.lbs.pojo.content.vo.ArticleVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ExecutionException;

@RestController
@Slf4j
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    //文章分页列表查询 查询入口页面 有三个 文章列表 草稿列表 小程序列表
    @GetMapping("/admin/content/article/list")
    public Result<PageResult<ArticleVO>> pageList(ArticleQuery articleQuery)
        throws BusinessException{
        return new Result<>(articleService.pageList(articleQuery));
    }

    //提交发布文章
    @PostMapping("/admin/content/article/insert")
    public Result<Void> insert(ArticleContentParam articleContentParam)
        throws BusinessException{
        articleService.insert(articleContentParam);
        return Result.success();
    }
    //小程序查询文章详情 阅读文章
    @GetMapping("/admin/content/article/get")
    public Result<ArticleVO> getDetail(Integer id) throws BusinessException {
        return new Result<>(articleService.detail(id));
    }

    //文章被提交了 点赞 收藏请求
    @PostMapping("/admin/content/article/behavior")
    public Result<Void> behave(ArticleActionParam param)
        throws BusinessException{
        articleService.behave(param);
        return Result.success();
    }

    //查询我曾经点赞和收藏的文章
    @GetMapping("/admin/content/article/getBehaviorList")
    public Result<ArticleActionPageResultVO> actionPage(ArticleQuery query) throws BusinessException, ExecutionException, InterruptedException {
        return new Result<>(articleService.actionPage(query));
    }
}
